import json,os

class ShowItem:
    def __init__(self, sId, keyName, key):
        self.sId = sId
        self.keyName = keyName
        self.key = key


class Config:
    backRadius:int = 4
    backOpacity:float = 0.8
    updateInterval = 10
    uiShowType = 0
    uiContent = []

    def __init__(self):
        pass

    def from_json(self, json_file):

        script_dir = os.path.dirname(os.path.abspath(__file__))         # 获取当前脚本所在的目录 
        jsonFile = os.path.join(script_dir, 'config.json')              # 构建 JSON 文件的完整路径 

        with open(jsonFile, 'r', encoding='utf-8') as file:
            data = json.load(file)

        self.backRadius = data["backRadius"],
        self.backOpacity = data["backOpacity"]
        self.updateInterval = data["updateInterval"]
        self.uiShowType = data["uiShowType"]

        self.uiContent.clear()
        for item in data["uiContent"]:
            self.uiContent.append({
                "id": item["id"],
                "Account": item["Account"],
                "title": item["title"],
                "show": [ShowItem(show_item["sId"], show_item["keyName"], show_item["key"]) for show_item in item["show"]]
            })

# config = Config()
# config.from_json("config.json")

# print("backRadius:", config.backRadius)
# print("backOpacity:", config.backOpacity)
# print("posX:", config.posX)
# print("posY:", config.posY)
# print("updateInterval:", config.updateInterval)
# print("uiShowType:", config.uiShowType)
# print("uiContent:")
# for item in config.uiContent:
#     print("\tId:", item["id"])
#     print("\tAccount:", item["Account"])
#     print("\tTitle:", item["title"])
#     print("\tShow:")
#     for show_item in item["show"]:
#         print("\t\tId:", show_item.sId)
#         print("\t\tKeyName:", show_item.keyName)
#         print("\t\tKey:", show_item.key)
